<template>
    <div>
    <common-head title="订单页"/>
    <div class="wrap">
  <van-contact-card 
    :type="contentType" 
    @click="choseContent"
    :name="content.linkMan"
    :tel="content.mobile" />
    </div>
<!-- 商品卡片 -->
<div class="items">
  <van-card
  v-for="item in items"
  :key="item.id"
  :num="item.number"
  :price="item.price"
  :title="item.name"
  :thumb="item.pic"
/>
</div>
     <!-- 提交订单 -->
<van-submit-bar :price="tatol*100" button-text="提交订单" @submit="onSubmit" />
    </div>
</template>

<script>
import CommonHead from '_components/commonHead.vue'
import { getDefaultContact , fetchCatesInfo} from '_api'
import { getToken } from '_utils'
    export default {
        data(){
            return{
               content:{
                   linkMan:'',
                   mobile:''
               },
               contentType:'add',
               items:[],
               tatol:0
            }
        },
        created(){
            this.getDefaultContact()
            this.fetchCatesInfo()
        },
        methods:{
            choseContent(){
                  if(this.contentType==='add'){
                      this.$router.push('/contentadd')
                  }else
                  {
                      this.$router.push('/contentlists')
                  }
            },
            onSubmit(){

            },
            getDefaultContact(){
                getDefaultContact({
                    token:getToken()
                }).then(res =>{
                    if(res.data.code===0){
                        console.log(res)
                        this.content=res.data.data.info
                        this.contentType='edit'
                    }
                  if(res.data.code===700){
                   this.contentType='add'
                  }
                })
            },
            fetchCatesInfo(){
                fetchCatesInfo({
                    token:getToken()
                }).then(res =>{
                if(res.data.code===0){
                    this.items=res.data.data.items.filter(item=>item.selected)
                    this.tatol=res.data.data.price
                }
                })
            }
        },
  components: {
       CommonHead 
       }  
    }

</script>

<style lang="scss" scoped>

</style>